<?
include_once($_SERVER['DOCUMENT_ROOT']."/lucy/config.php");
include_once(INC.'sess.php');
include_once(CLA."lucy_feelings.class.php");
include_once(CLA."speech.class.php");

$lucy_feeling = new Lucy_feelings();

$word = str_replace("+", " ", $_SESSION['edit']['word']);

$type = ($_POST['type'] == "other") ? $_POST['type_other'] : $_POST['type'];

if($type != "" AND $_POST['feeling'] != ""){

	$type = str_replace(" ", "+", $type);
	$feeling = $_POST['feeling'];
	
	$speech = new Speech();
	$id = $speech->get_id($_SESSION['edit']['word']);
	
	$speech->set_id($id);
	$speech->set_feeling($feeling);
	$speech->set_type($type);
	
	if($speech->update()){
		//	LUCY EMOTIONAL RESPONSE
		if($feeling < 3){
			$lucy_feeling->change(-1);
		}elseif($feeling > 3){
			$lucy_feeling->change(+1);
		}
		$_SESSION['print']['echo'] = "Izmainīts vārds <u><b>$word</b></u>";
		$mod_name = "print";
		$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
		echo $send;
	}
}elseif($_POST['cancel'] == 1){
		$_SESSION['print']['echo'] = "Neko nesaglabāju :(";
		$lucy_feeling->change(-1);
		$mod_name = "print";
		$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
		echo $send;
}


$wrd = new Speech();
$wrd->set_word($_SESSION['edit']['word']);
?>
<form action="" method="POST">
	<table border="0">
		<tr>
			<td>
				vārds:
			</td>
			<td>
				<b><?=$word;?></b>
			</td>
		</tr>
		<tr>
			<td>
				tips:
			</td>
			<td><?
				$type_arr = get_all_types();
				?>
				<select name="type">
					<option value=""></option>
					<?
					foreach($type_arr AS $name){ 
						if($wrd->get_type() == $name){ $selected = "selected"; }else{ $selected = ""; }
						echo "<option value='$name' $selected>$name</option>";
					} ?>
					<option value="other" onclick="javascript:onclick(select_other())">cits</option>
				</select>
				<input id = "type_other" style="visibility:hidden;" type="text" name="type_other"/>
			</td>
		</tr>
		<tr>
			<td>
				feeling:
			</td>
			<td>
				<select name="feeling">
					<? for ($i=1;$i<=5;$i++){ ?>
						<? if($wrd->get_feeling() == $i){ $selected = "selected"; }else{ $selected = ""; } ?>
						<option value="<?=$i;?>" <?=$selected;?>><?=$i;?></option>
					<? } ?>
				</select>
			</td>
		</tr>		
		<tr>
			<td>
				
			</td>
			<td>
				<input type="submit" name="submit" value="Saglabāt">
			</td>
		</tr>
	</table>
</form>

<script>
function select_other(){
	document.getElementById("type_other").style.visibility = "visible";
}
</script>